
#include <stdio.h>
#include <stdlib.h>

#include <unistd.h>
#include <string.h>

#include <errno.h>
#include <pty.h>

#include <unistd.h>
#include <fcntl.h>

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>


const static char *domain_list[]={
	"kuaidadi.com",
	"restapi.amap.com",
	"apilocate.amp.com",
	"utop.umengcloud.com",
	"kuaidi.com",
	"diditaxi.com.cn",
	"didialift.com",
	"vectors.map.qq.com",
	"elemecdn.com",
	"ele.me",
	"m.jd.com",
	"kuaidadi.com",
	"restapi.amap.com",
	"apilocate.amp.com",
	"utop.umengcloud.com",
	"kuaidi.com",
	"sogou.com",
	"m.account.sogou.com",
	"input.shouji.sogou.com",
	"img.shouji.sogou.com",
	"wap.dl.pinyin.sogou.com",
	"taobao.com",
	"adash.m.taobao.com",
	"imcloud.taobao.org",
	"api.m.taobao.com",
	"m.taobao.com",
	"wbapp.mobile.sina.cn",
	"sdkapp.mobile.sina.cn",
	"short.weixin.qq.com",
	"long.weixin.qq.com",
	"ximalaya.com",
	"diditaxi.com.cn",
	"didialift.com",
	"vectors.map.qq.com",
	"m.jd.com",
	"sdkapp.mobile.sina.cn",
	"wbapp.mobile.sina.cn",
	NULL,
};


static const char* strstri(const char* str, const char* subStr)
{
	int str_len = 0;
	int subStr_len = 0;

	if(NULL == str || NULL == subStr){
		return NULL;
	}

	str_len = strlen(str);

	subStr_len = strlen(subStr);
	if(subStr_len == 0){
		return NULL;
	}

	if(str_len < subStr_len){
		return NULL;
	}

	while(*str) {
		if(strncasecmp(str, subStr, subStr_len) == 0) {
		   return str;
		}
		++str;
	}

	return NULL;
}

static int add_domain_ip(const unsigned char *domain, const unsigned char *ip)
{
	int ret = 0;
	int domain_idx = 0;

	if(domain == NULL || ip == NULL){
		return -1;
	}

//	log_info("size: %zu  %zu\n", sizeof(domain_list), sizeof(const char *));
	printf("size: %zu  %zu\n", sizeof(domain_list), sizeof(const char *));

	for(domain_idx = 0; domain_idx <= sizeof(domain_list)/sizeof(const char *); domain_idx++){
		if(domain_list[domain_idx]){
		//	log_info("compare %s vs. %s", domain, domain_list[domain_idx]);
			printf("compare %s vs. %s\n", domain, domain_list[domain_idx]);
			if(strstri((const char *)domain, domain_list[domain_idx]) != NULL){
			//	log_info("add %s", domain);
				printf("add %s\n", domain);
				goto do_add;
			}
		}
	}

//	log_info("drop %s", domain);
	printf("drop %s\n", domain);
	return -1;


do_add:
	printf("do add!\n");

	return ret;

}


static int test_add_domain_ip()
{
	const unsigned char *domain1 = "www.baidu.com";
	const unsigned char *domain2 = "kuaidadi.com";
	const unsigned char *domain3 = "wbapp.mobile.sina.cn";
	const unsigned char *domain4 = "a.wbapp.mobile.sina.cn";
	const unsigned char ip[4] = {115, 239, 210, 27};

	add_domain_ip(domain1, ip);
	add_domain_ip(domain2, ip);
	add_domain_ip(domain3, ip);
	add_domain_ip(domain4, ip);

	exit(0);

	return 0;
}



int main(int argc, const char *argv[])
{

	test_add_domain_ip();



    return 0x00;
}




